package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <h1>分发目标</h1>
 * @Author: crowsjian
 * @Date: 2020/6/1 21:46
 */
@Getter
@AllArgsConstructor
public enum DistributeTarget {
    SINGLE("单用户",1),
    MULTI("多用户",2),
    ;
    private String description;//分发目标描述
    private Integer code;//分发目标编码
    public static DistributeTarget of(Integer code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean->bean.code.equals(code))
                .findAny()
                .orElseThrow(()->new IllegalArgumentException(code + "not exists!"));
    }
}
